package com.example.servicedemo1;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

public class MyService extends Service {
  private static final String CHANNEL_ID="前台服务信道id";
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder();
    }
    class  MyBinder extends IMyAidlInterface.Stub{

        @Override
        public String getRemoteData(String data) throws RemoteException {
            String result="aidl服务端收到"+data;
            return result;
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        NotificationChannel channel=new NotificationChannel(CHANNEL_ID,"前台服务", NotificationManager.IMPORTANCE_DEFAULT);
        //设置锁屏完全可见
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationManagerCompat nmc=NotificationManagerCompat.from(this);
        nmc.createNotificationChannel(channel);
        Notification notification=new NotificationCompat.Builder(this,CHANNEL_ID)
                .setContentTitle("前台服务通知标题")
                .setContentText("前台服务通知内容")
                .setSmallIcon(R.mipmap.ic_launcher).build();
        startForeground(1,notification);
    }
}